package com.aos.iot.socket.common.store;


import com.aos.iot.socket.common.message.Message;
import com.aos.iot.socket.common.store.pubsub.PubSubStore;
import com.aos.iot.socket.common.store.pubsub.RedissonPubSubStore;
import org.redisson.api.RedissonClient;

public class RedissonStoreFactory<M extends Message> implements StoreFactory<M> {

    private final RedissonClient redisClient;
    private final RedissonClient redisPub;
    private final RedissonClient redisSub;

    private final PubSubStore<M> pubSubStore;

    public RedissonStoreFactory(RedissonClient redisClient) {
        this.redisClient = redisClient;
        this.redisPub = redisClient;
        this.redisSub = redisClient;

        this.pubSubStore = new RedissonPubSubStore<>(redisPub, redisSub);
    }

    @Override
    public PubSubStore<M> pubSubStore() {
        return pubSubStore;
    }

    @Override
    public Store createStore(String channelId) {
        return new RedissonStore(channelId, redisClient);
    }

    @Override
    public void shutdown() {
        redisClient.shutdown();
        redisPub.shutdown();
        redisSub.shutdown();
    }
}
